<?=view('admin.common.header')?>
<?=view('admin.common.nav')?>
<div class="container">
    <div class="row">
        <?php if($products && count($products)): ?>
        <div class="panel panel-default">
            <div class="panel-heading">
                商品列表<a href="<?= url("admin/product/add") ?>" class="btn btn-success btn-xs eveAdd" style="float: right;">添加商品</a>
            </div>
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th> 产品名称</th>
                        <th> 产品价格</th>
                        <th> 产品描述</th>
                        <th> 产品类型</th>
                        <th> 地区</th>
                        <th> 平台优惠</th>
                        <th> 产品时长</th>
                        <th> 产品属于</th>
                        <th> 产品排序</th>
                        <th>#</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($products as $val): ?>
                    <tr>
                        <td><?=$val->name?></td>
                        <td><?=$val->price?></td>
                        <td><?=$val->desc?></td>
                        <td><?=$val->strPtype()?></td>
                        <td><?=$area[$val->area]?></td>
                        <td><?=$val->pfav?></td>
                        <td><?=$val->lot?></td>
                        <td><?=$val->strPcate()?></td>
                        <td><?=$val->sort?></td>
                        <td>
                            <a href="<?=url("admin/product/edit/{$val->id}")?>" class="btn btn-info btn-xs eveModify">修改</a>
                            <a href="<?=url("admin/product/edit/{$val->id}/0")?>" class="btn btn-danger btn-xs eveDel">删除</a>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <?=$products->render()?>
        <?php endif; ?>
    </div>
</div>
<script>
    $('.eveDel').click(function() {
        var $url = $(this).attr('href');
        layer.confirm('确定要删除该产品吗？', {icon: 3, title:'删除'}, function(index){
            $.get($url, function(data){
               layer.msg(data.info);
               if(data.status == 1) {
                   window.location.reload();
               }
            });
            layer.close(index);
        });
        return false;
    });
    $('.eveModify').click(function(){
        var $url = $(this).attr('href');
        layer.open({
            type: 2,
            title: '商品修改',
            shadeClose: false,
            shade: 0.8,
            area: ['480px', '600px'],
            content:  $url,
        });
        return false;
    });
     $('.eveAdd').click(function(){
        var $url = $(this).attr('href');
        layer.open({
            type: 2,
            title: '商品添加',
            shadeClose: false,
            shade: 0.8,
            area: ['480px', '600px'],
            content:  $url,
        });
        return false;
    });
</script>
<?=view('admin.common.footer')?>